$(function () {
    $(".nav_order_bar_main").find("li").click(function () {
        var tagId = $(this).attr("id");
        var showType = 1;//1: everyoneOrderTag  2:myOrder
        if (tagId == 'everyoneOrderTag') {
            showType = 1;
            $("#everyoneOrderTag").addClass("active_order_sel").removeClass("active_order_normal")
            $("#myOrderTag").addClass("active_order_normal").removeClass("active_order_sel");
        } else {
            showType = 2;
            $("#everyoneOrderTag").addClass("active_order_normal").removeClass("active_order_sel");
            $("#myOrderTag").addClass("active_order_sel").removeClass("active_order_normal")
        }
        queryOrderList(showType);
    })


    queryOrderList(1);

    // 获取公告
    queryNotice();

    $("#myPhoto").click(function () {
        $("#headPhotoNotice").css("display", "");
    });

    $("#ikownBtn").click(function () {
        $("#headPhotoNotice").css("display", "none");
    });
})

function noclick(t) {
    var ppp = $(t).parent().parent().parent();
    ppp.css("display", "none");
    var noticeId = ppp.attr("lang");
    var data = {noticeId: noticeId}
    $.ajax({
        type: "post",
        url: "../notice/saveUserNotice",
        contentType: "application/x-www-form-urlencoded",
        data: data,
        success: function (msg) {
        }
    })
}

// 获取公告
function queryNotice() {
    $.ajax({
        type: "get",
        url: "../notice/queryNotice",
        dataType: "json",
        contentType: "application/json",
        success: function (msg) {
            var l = msg.data;
            var html = "";
            for (var i = 0; i < l.length; i++) {
                var n = l[i];
                html += "<div data-v-120b09c7=\"\" data-v-53f33387=\"\" class=\"normal_notice_zz\" lang=\"" + n.id + "\">\n" +
                    "            <div data-v-120b09c7=\"\" class=\"normal_wrapper\">\n" +
                    "                <button data-v-120b09c7=\"\" class=\"icon_question\" style=\"display: none;\">?</button>\n" +
                    "                <p data-v-120b09c7=\"\" class=\"normal_tz_title\">" + n.noticeTitle + "</p>\n" +
                    "                <p data-v-120b09c7=\"\" class=\"normal_tz_info\">" + n.noticeContent + "</p>\n" +
                    "                <div data-v-120b09c7=\"\" class=\"normal_tz_close\">\n" +
                    "                    <button data-v-120b09c7=\"\" class=\"tz_close_right\" style='width: 100%' onclick='noclick(this)'>close</button>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "        </div>"
            }
            $("#myNoticeDiv").html(html);
        }
    })

}

//订单查询
function queryOrderList(showType) {
    var data = {
        showType: showType,
    }
    $.ajax({
        type: "get",
        url: "../bet/queryOrderList",
        dataType: "json",
        contentType: "application/json",
        data: data,
        success: function (msg) {
            var orderList = msg.data.betList;
            var clientUser = msg.data.clientUser;
            var res = "";
            for (var i = 0; i < orderList.length; i++) {
                var order = orderList[i];
                var betType = order.betType == undefined ? "" : order.betType;
                var winAmount = order.winAmount == undefined ? 0 : order.winAmount;
                var betCost = order.betCost == undefined ? 0 : order.betCost;
                var winAmount = order.winAmount == undefined ? 0 : order.winAmount;
                var loginName = cutString(order.loginName, 6);
                var betType = order.betType;
                var betNumber = order.betNumber;
                var betColor = order.betColor;
                var betTypeHtml = "";
                if (betType == 0) {
                    //green
                } else if (betType == 1) {
                    //purple
                } else if (betType == 2) {
                    //red
                    betTypeHtml = "<div data-v-2add742c=\"\" class=\"record_body record_body_red\">R</div>";
                } else {
                    betTypeHtml = "<div data-v-2add742c=\"\" class=\"record_body record_body_gray\">3</div>";
                }

                var zjxx = "";
                if (betType != 0) {
                    zjxx = "<div data-v-2add742c=\"\" class=\"record_body record_body_gray\">" + betNumber + "</div>";
                } else {
                    //绿色0，红色2，violet 1
                    if (betColor == 0) {
                        zjxx = "<div data-v-2add742c=\"\" class=\"record_body record_body_green\">G</div>";
                    } else if (betColor == 2) {
                        zjxx = "<div data-v-2add742c=\"\" class=\"record_body record_body_red\">R</div>";
                    } else {
                        zjxx = "<div data-v-2add742c=\"\" class=\"record_body record_body_violet\">V</div>";
                    }
                }

                var userOrderContent = "";
                if (winAmount == 0) {
                    userOrderContent = "<div data-v-2add742c=\"\" class=\"user_order_item_content\">-₹" + betCost + "</div>"
                } else {
                    userOrderContent = "<div data-v-2add742c=\"\" class=\"user_order_item_content\">+₹" + winAmount + "</div>"
                }

                res += "<li data-v-2add742c=\"\" class=\"li_othor\">\n" +
                    "       <div data-v-2add742c=\"\" class=\"user_order_item\">" +
                    "          <div data-v-2add742c=\"\" class=\"user_order_item_content_long2\">" +
                    "               <span data-v-2add742c=\"\" class=\"user_order_item_content_sn\">" +
                    order.periodCode +
                    "               </span>" +
                    "          </div>" +
                    "          <div data-v-2add742c=\"\" class=\"user_order_item_content_long\">" +
                    "           <img data-v-2add742c=\"\"  src=\"img/vip" + clientUser.vipLevel + ".png\"   alt=\"\">" +
                    "                <span  data-v-2add742c=\"\">" + loginName + "</span>" +
                    "          </div>" +
                    "          <div data-v-2add742c=\"\" class=\"user_order_item_content_short\">" +
                    zjxx +
                    betTypeHtml +
                    "          </div>" + userOrderContent +
                    "       </div>" +
                    "    </li>";
            }
            $("#orderListView").html(res);
        }
    })
}

/**参数说明：

 * 根据长度截取先使用字符串，超长部分追加…

 * str 对象字符串

 * len 目标字节长度

 * 返回值： 处理结果字符串

 */

function cutString(str, len) {
    //length属性读出来的汉字长度为1
    var end = str.substring(str.length - 3, str.length);
    if (str.length * 2 <= len) {
        return str;
    }
    var strlen = 0;
    var s = "";
    for (var i = 0; i < str.length; i++) {
        s = s + str.charAt(i);
        if (str.charCodeAt(i) > 128) {
            strlen = strlen + 2;
            if (strlen >= len) {
                return s.substring(0, s.length - 1) + "***" + end;
            }
        } else {
            strlen = strlen + 1;
            if (strlen >= len) {
                return s.substring(0, s.length - 2) + "***" + end;
            }
        }
    }
    return s;
}

